package day0228;

public class Exer02 {

    public static void main(String[] args) {
        String str ="abccba";

        System.out.println(isReverse2(str));
    }

    static boolean isReverse(String str) {
        if (str != null) {
//            StringBuilder stringBuffer = new StringBuilder(str);
//            String reverse = stringBuffer.reverse().toString();
//            return str.equals(reverse);

            StringBuilder sb = new StringBuilder();

            for (int i = str.length() - 1; i >= 0; i--) {
                char c = str.charAt(i);
                sb.append(c);
            }
            return sb.toString().equals(str);
        }

        return false;
    }

    static boolean isReverse2(String str) {
        if (str != null){
            for (int i = 0; i < str.length() / 2; i++) {
                char pre = str.charAt(i);
                char sub = str.charAt(str.length() - i - 1);
                if (pre != sub) {
                    return false;
                }
            }
            return true;
        }
        return false;
    }

}
